package com.touchealth.test.aliyun.oss;

import cn.hutool.poi.excel.ExcelReader;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.OSSObject;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;

/**
 * @author zhangyanqiang
 * @date 2021/10/26
 **/
@Slf4j
public class OssOperation {

    public static void main(String[] args) {
        try {
            String endpoint = "oss-cn-hangzhou.aliyuncs.com";
            String accessKeyId = "LTAI5tDbvL32Q6mUkyedrqdZ";
            String accessKeySecret = "JkahtIQzVYgUflQmtghM1dcmd2BYsG";
            String bucketName = "sckj-accounting";
            String objectName = "test/external/reservation/yjk_meinian/2021-09-28/预约信息160948.xlsx";

            OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

            OSSObject ossObject = ossClient.getObject(bucketName, objectName);

            System.out.println("Object content:");
            ExcelReader excelReader = new ExcelReader(ossObject.getObjectContent(), 0, true);
            List<Map<String, Object>> readAll = excelReader.readAll();


            readAll.forEach(r ->{
                log.info("data:{}",r.values());
            });
            ossClient.shutdown();
        }catch (Exception e){
          log.error("error",e);
        }


    }
}
